﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using YArchitech.BIM;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Plumbing;

namespace YArchitech.HVAC
{
	public partial class FrmDefinePipes : System.Windows.Forms.Form
	{
		public FrmDefinePipes(Autodesk.Revit.DB.Document doc)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			this.doc = doc;
			base.ImeMode = ImeMode.Disable;
			this.ptCalOperate = new SprinklerCalOperate();
			this.colPtnum.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.colDiameter.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
		}

		public bool GetBeReflectedKValue()
		{
			return this.ckbKValue.Checked;
		}

		public int GetMarkMinDiameter()
		{
			int result = 20;
			try
			{
				result = Convert.ToInt32(this.hyTxtMinDia.Text);
			}
			catch (Exception ex)
			{
				ex.ToString();
				result = 20;
			}
			return result;
		}

		public double GetFontHeight()
		{
			double result = 2.5;
			try
			{
				result = Convert.ToDouble(this.hyTxtFontHeight.Text);
			}
			catch (Exception ex)
			{
				ex.ToString();
				result = 2.5;
			}
			return result;
		}

		public double GetDistanceToPipeLine()
		{
			double result = 2.0;
			try
			{
				result = Convert.ToDouble(this.hyTxtDistanceToLine.Text);
			}
			catch (Exception ex)
			{
				ex.ToString();
				result = 2.0;
			}
			return result;
		}

		public bool GetBeDeletedTag()
		{
			return !this.ckbKeepLocation.Checked;
		}

		private void btnExit_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void btnEnsure_Click(object sender, EventArgs e)
		{
			if (!this.JudgeSettingValue())
			{
				return;
			}
			this.SaveUserSetting();
			string a = this.editInfo;
			if (!(a == "添加"))
			{
				if (!(a == "修改"))
				{
					List<Fire_PtDn> listFirePtDn = this.ptCalOperate.GetListFirePtDn(this.dangerId);
					int index = this.dgvFirePtNumInfo.SelectedRows[0].Index;
					this.BindDGVInfo(listFirePtDn, false);
					this.dgvFirePtNumInfo.Rows[index].Selected = true;
				}
				else
				{
					if (this.isAdd)
					{
						this.AddDangerInfo(true);
						this.isAdd = false;
					}
					this.ModifyInfo();
				}
			}
			else
			{
				this.AddDangerInfo(false);
			}
			this.RefreshFirePtDnInfo();
			int count = this.dgvFirePtNumInfo.Rows.Count;
			this.dgvFirePtNumInfo.Rows[count - 1].Selected = true;
		}

		private void ModifyInfo()
		{
			new Fire_PtDn();
			for (int i = 0; i < this.dgvFirePtNumInfo.Rows.Count; i++)
			{
				Fire_PtDn fire_PtDn = new Fire_PtDn();
				fire_PtDn.Id = Convert.ToInt32(this.dgvFirePtNumInfo.Rows[i].Cells["colId"].Value);
				fire_PtDn.Diameter = Convert.ToInt32(this.dgvFirePtNumInfo.Rows[i].Cells["colDiameter"].Value);
				fire_PtDn.SprinklerNum = Convert.ToInt32(this.dgvFirePtNumInfo.Rows[i].Cells["colPtnum"].Value);
				this.ptCalOperate.GetFirePtDn(fire_PtDn.Id);
				if (this.ModifyDiamAndSprinkNum(fire_PtDn.Diameter, fire_PtDn.SprinklerNum, fire_PtDn.Id))
				{
					this.sqlStr = string.Format("update  [Fire_PtDN] set DN={0},ptnum={1} where id={2}", fire_PtDn.Diameter, fire_PtDn.SprinklerNum, fire_PtDn.Id);
					if (this.ptCalOperate.ExecuteCmdPT(this.sqlStr))
					{
						this.editInfo = "";
					}
				}
			}
			int index = this.dgvFirePtNumInfo.SelectedRows[0].Index;
			YJKMessageBox.Show("修改成功！", MessageBoxButtons.OK);
			List<Fire_PtDn> listFirePtDn = this.ptCalOperate.GetListFirePtDn(this.dangerId);
			this.BindDGVInfo(listFirePtDn, false);
			this.dgvFirePtNumInfo.Rows[index].Selected = true;
		}

		private bool ModifyDiamAndSprinkNum(int diameter, int ptNum, int id)
		{
			foreach (Fire_PtDn fire_PtDn in this.ptCalOperate.GetListFirePtDn(this.dangerId))
			{
				if (id != fire_PtDn.Id && (diameter == fire_PtDn.Diameter || ptNum == fire_PtDn.SprinklerNum))
				{
					return false;
				}
			}
			return true;
		}

		private void AddDangerInfo(bool bl = false)
		{
			if (this.JudgeValueIsNum() != null)
			{
				YJKMessageBox.Show(this.JudgeValueIsNum(), MessageBoxButtons.OK);
				return;
			}
			List<Fire_PtDn> list = new List<Fire_PtDn>();
			foreach (object obj in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
			{
				DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
				if ((AddSprinklerDiameter)dataGridViewRow.Cells["colAddInfo"].Value == AddSprinklerDiameter.YES)
				{
					list.Add(new Fire_PtDn
					{
						Id = Convert.ToInt32(dataGridViewRow.Cells["colId"].Value),
						SprinklerNum = Convert.ToInt32(dataGridViewRow.Cells["colPtnum"].Value),
						Diameter = Convert.ToInt32(dataGridViewRow.Cells["colDiameter"].Value),
						DangerId = Convert.ToInt32(dataGridViewRow.Cells["colDanId"].Value),
						AddInfo = AddSprinklerDiameter.NO
					});
				}
			}
			int num = 0;
			foreach (Fire_PtDn fire_PtDn in list)
			{
				if (!this.JudgeDiamAndSprinkNum(fire_PtDn.Diameter, fire_PtDn.SprinklerNum))
				{
					YJKMessageBox.Show("管径或喷头数\n不能与表中数据相同！", MessageBoxButtons.OK);
					return;
				}
				string sql = string.Format("insert into  [Fire_PtDN] (dangerid,DN,ptnum) values ({0},{1},{2})", fire_PtDn.DangerId, fire_PtDn.Diameter, fire_PtDn.SprinklerNum);
				if (!this.ptCalOperate.ExecuteCmdPT(sql))
				{
					YJKMessageBox.Show("添加失败！", MessageBoxButtons.OK);
					return;
				}
				num++;
			}
			if (num > 0)
			{
				YJKMessageBox.Show("添加成功" + num + "数据！", MessageBoxButtons.OK);
				this.editInfo = "";
			}
			if (!bl)
			{
				List<Fire_PtDn> listFirePtDn = this.ptCalOperate.GetListFirePtDn(this.dangerId);
				this.BindDGVInfo(listFirePtDn, false);
			}
		}

		private void FrmDefinePipes_Load(object sender, EventArgs e)
		{
			try
			{
				this.BindWxdjInfo();
				string text = new ModelAnalyser(this.doc).GetDangerLevel();
				if (text == null)
				{
					text = "中危险等级II";
				}
				int num = 0;
				while (num < this.cboWxdj.Items.Count && !(this.cboWxdj.Items[num] as Fire_Danger).DangerLevel.Equals(text))
				{
					num++;
				}
				this.cboWxdj.SelectedIndex = num;
				this.cboK.Items.AddRange(new object[]
				{
					"80",
					"320"
				});
				this.GetUserSetting();
				this.RefreshFirePtDnInfo();
			}
			catch (Exception)
			{
				throw;
			}
		}

		private void BindWxdjInfo()
		{
			this.cboWxdj.ValueMember = "Id";
			this.cboWxdj.DisplayMember = "DangerLevel";
			this.cboWxdj.DataSource = this.ptCalOperate.GetListFireDanger();
			this.cboWxdj.SelectedValue = this.dangerId;
			this.dangerId = Convert.ToInt32(this.cboWxdj.SelectedValue);
		}

		private void cboWxdj_SelectedIndexChanged(object sender, EventArgs e)
		{
			try
			{
				this.dangerId = Convert.ToInt32(this.cboWxdj.SelectedValue);
				this.RefreshFirePtDnInfo();
			}
			catch (Exception)
			{
				throw;
			}
		}

		private void cboK_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.K = Convert.ToDouble(this.cboK.Text);
			if (this.cboK.SelectedIndex == 1)
			{
				this.chkMin.Checked = true;
				this.chkMin.Enabled = false;
				this.hyTxtMin.Text = "40";
				this.hyTxtMin.Enabled = false;
				return;
			}
			this.chkMin.Enabled = true;
			this.hyTxtMin.Enabled = true;
		}

		private void RefreshFirePtDnInfo()
		{
			this.listPtNum = this.ptCalOperate.GetListFirePtDn(this.dangerId);
			this.listPtNum.Sort((Fire_PtDn x, Fire_PtDn y) => x.Diameter.CompareTo(y.Diameter));
			this.BindDGVInfo(this.listPtNum, false);
			this.txtMaxDia.Text = Convert.ToString(this.listPtNum.Last<Fire_PtDn>().Diameter);
		}

		private void BindDGVInfo(List<Fire_PtDn> listInfo, bool readInfo)
		{
			this.dgvFirePtNumInfo.DataSource = listInfo;
			this.dgvFirePtNumInfo.AllowUserToAddRows = false;
			this.dgvFirePtNumInfo.ReadOnly = readInfo;
		}

		private void GetUserSetting()
		{
			int sprinklerPara = this.ptCalOperate.GetSprinklerPara("DangerID");
			if (this.cboWxdj.Items.Count >= sprinklerPara)
			{
				this.cboWxdj.SelectedIndex = sprinklerPara;
			}
			else
			{
				this.cboWxdj.SelectedIndex = 0;
			}
			this.cboK.Text = this.ptCalOperate.GetSprinklerPara("K").ToString();
			this.chkMin.Checked = (this.ptCalOperate.GetSprinklerPara("LimitMin") == 0);
			this.hyTxtMin.Text = this.ptCalOperate.GetSprinklerPara("MinDiameter").ToString();
			bool @checked = true;
			this.ptCalOperate.GetSprinklerMarkPara("BeReflectK", ref @checked);
			this.ckbKValue.Checked = @checked;
			bool checked2 = true;
			this.ptCalOperate.GetSprinklerMarkPara("BeKeep", ref checked2);
			this.ckbKeepLocation.Checked = checked2;
			this.hyTxtMinDia.Text = this.ptCalOperate.GetSprinklerPara("MinDiameter").ToString();
			double num = 0.1;
			this.ptCalOperate.GetSprinklerMarkPara("FontHeight", ref num);
			this.hyTxtFontHeight.Text = num.ToString();
			double num2 = 0.0;
			this.ptCalOperate.GetSprinklerMarkPara("DistanceToLine", ref num2);
			this.hyTxtDistanceToLine.Text = num2.ToString();
			if (this.ptCalOperate.GetSprinklerPara("blMachinery").ToString() == "0")
			{
				this.cbThreeFour.Checked = false;
				return;
			}
			this.cbThreeFour.Checked = true;
		}

		private void SaveUserSetting()
		{
			this.ptCalOperate.SaveSprinklerPara((double)this.cboWxdj.SelectedIndex, "DangerID");
			this.ptCalOperate.SaveSprinklerPara(this.K, "K");
			this.ptCalOperate.SaveSprinklerPara((double)int.Parse(this.hyTxtMin.Text), "MinDiameter");
			this.ptCalOperate.SaveSprinklerPara((double)(this.chkMin.Checked ? 0 : 1), "LimitMin");
			this.ptCalOperate.SaveSprinklerPara(this.ckbKeepLocation.Checked.ToString(), "BeKeep");
			this.ptCalOperate.SaveSprinklerPara(this.ckbKValue.Checked.ToString(), "BeReflectK");
			this.ptCalOperate.SaveSprinklerPara(this.GetTxtDoubleValue("MinDiameter"), "MinDiameter");
			this.ptCalOperate.SaveSprinklerPara(this.GetTxtDoubleValue("FontHeight"), "FontHeight");
			this.ptCalOperate.SaveSprinklerPara(this.GetTxtDoubleValue("DistanceToLine"), "DistanceToLine");
			if (this.cbThreeFour.Checked)
			{
				this.ptCalOperate.SaveSprinklerPara("1", "blMachinery");
				return;
			}
			this.ptCalOperate.SaveSprinklerPara("0", "blMachinery");
		}

		private string GetTxtDoubleValue(string keyStr)
		{
			string result = "";
			try
			{
				double num = 1.0;
				if (!(keyStr == "MinDiameter"))
				{
					if (!(keyStr == "FontHeight"))
					{
						if (keyStr == "DistanceToLine")
						{
							num = Convert.ToDouble(this.hyTxtDistanceToLine.Text);
						}
					}
					else
					{
						num = Convert.ToDouble(this.hyTxtFontHeight.Text);
					}
				}
				else
				{
					num = Convert.ToDouble(this.hyTxtMinDia.Text);
				}
				result = num.ToString();
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				if (!(keyStr == "MinDiameter"))
				{
					if (!(keyStr == "FontHeight"))
					{
						if (keyStr == "DistanceToLine")
						{
							result = "3";
						}
					}
					else
					{
						result = "2.5";
					}
				}
				else
				{
					result = "25";
				}
			}
			return result;
		}

		private void btnAdd_Click(object sender, EventArgs e)
		{
			if (this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"].Value.ToString() == "0")
			{
				this.dgvFirePtNumInfo.EndEdit();
				this.dgvFirePtNumInfo.EditMode = DataGridViewEditMode.EditOnEnter;
				this.dgvFirePtNumInfo.CurrentCell = this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"];
				this.dgvFirePtNumInfo.BeginEdit(true);
				return;
			}
			List<Fire_PtDn> list = new List<Fire_PtDn>();
			foreach (object obj in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
			{
				DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
				list.Add(new Fire_PtDn
				{
					Id = Convert.ToInt32(dataGridViewRow.Cells["colId"].Value),
					SprinklerNum = Convert.ToInt32(dataGridViewRow.Cells["colPtnum"].Value),
					Diameter = Convert.ToInt32(dataGridViewRow.Cells["colDiameter"].Value),
					DangerId = Convert.ToInt32(dataGridViewRow.Cells["colDanId"].Value),
					AddInfo = (AddSprinklerDiameter)dataGridViewRow.Cells["colAddInfo"].Value
				});
			}
			list.Add(new Fire_PtDn
			{
				Id = 0,
				DangerId = this.dangerId,
				SprinklerNum = 0,
				Diameter = 0,
				AddInfo = AddSprinklerDiameter.YES
			});
			this.BindDGVInfo(list, false);
			this.dgvFirePtNumInfo.ClearSelection();
			int num = 0;
			foreach (object obj2 in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
			{
				DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
				if (Convert.ToString(dataGridViewRow2.Cells["colPtnum"].Value) == Convert.ToString(0))
				{
					num = dataGridViewRow2.Index;
					this.rowIndex = dataGridViewRow2.Index;
				}
			}
			this.dgvFirePtNumInfo.Rows[num].Selected = true;
			this.dgvFirePtNumInfo.Rows[num].Visible = true;
			this.dgvFirePtNumInfo.FirstDisplayedScrollingRowIndex = num;
			this.dgvFirePtNumInfo.CurrentCell = this.dgvFirePtNumInfo.Rows[num].Cells["colPtnum"];
			this.dgvFirePtNumInfo.BeginEdit(true);
			this.editInfo = "添加";
			this.isAdd = true;
		}

		public string JudgeValueIsNum()
		{
			string text = null;
			string input = this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"].Value.ToString().Trim();
			string input2 = this.dgvFirePtNumInfo.SelectedRows[0].Cells["colPtnum"].Value.ToString().Trim();
			if (!Regex.IsMatch(input, "^[1-9]+\\d*$"))
			{
				text = "直径必须为正整数！";
			}
			if (!Regex.IsMatch(input2, "^[1-9]+\\d*$"))
			{
				text += "\n喷头数必须是正整数！";
			}
			return text;
		}

		private bool JudgeDiamAndSprinkNum(int diameter, int sprinklerNum)
		{
			this.listPtNum = this.ptCalOperate.GetListFirePtDn(this.dangerId);
			foreach (Fire_PtDn fire_PtDn in this.listPtNum)
			{
				if (diameter == fire_PtDn.Diameter || sprinklerNum == fire_PtDn.SprinklerNum)
				{
					return false;
				}
			}
			return true;
		}

		private void btnDelete_Click(object sender, EventArgs e)
		{
			this.blCheckTrue = false;
			try
			{
				if (this.dgvFirePtNumInfo.Rows.Count > 1)
				{
					int num = Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colId"].Value);
					Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colPtnum"].Value);
					Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"].Value);
					if (num != 0)
					{
						if (YJKMessageBox.Show("确认要删除吗", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
						{
							string sql = string.Format("delete from [Fire_PtDN] where id ={0}", num);
							if (this.ptCalOperate.ExecuteCmdPT(sql))
							{
								YJKMessageBox.Show("删除成功！", MessageBoxButtons.OK);
								List<Fire_PtDn> list = new List<Fire_PtDn>();
								foreach (object obj in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
								{
									DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
									Fire_PtDn fire_PtDn = new Fire_PtDn();
									fire_PtDn.Id = Convert.ToInt32(dataGridViewRow.Cells["colId"].Value);
									fire_PtDn.SprinklerNum = Convert.ToInt32(dataGridViewRow.Cells["colPtnum"].Value);
									fire_PtDn.Diameter = Convert.ToInt32(dataGridViewRow.Cells["colDiameter"].Value);
									fire_PtDn.DangerId = Convert.ToInt32(dataGridViewRow.Cells["colDanId"].Value);
									if ((AddSprinklerDiameter)dataGridViewRow.Cells["colAddInfo"].Value == AddSprinklerDiameter.YES)
									{
										fire_PtDn.AddInfo = AddSprinklerDiameter.YES;
									}
									else
									{
										fire_PtDn.AddInfo = AddSprinklerDiameter.NO;
									}
									list.Add(fire_PtDn);
								}
								int index = this.dgvFirePtNumInfo.CurrentRow.Index;
								list.RemoveAt(index);
								list.Sort((Fire_PtDn x, Fire_PtDn y) => x.Diameter.CompareTo(y.Diameter));
								this.BindDGVInfo(list, false);
								this.txtMaxDia.Text = Convert.ToString(list.Last<Fire_PtDn>().Diameter);
							}
							else
							{
								YJKMessageBox.Show("删除失败！", MessageBoxButtons.OK);
							}
						}
					}
					else
					{
						List<Fire_PtDn> list2 = new List<Fire_PtDn>();
						foreach (object obj2 in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
						{
							DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
							list2.Add(new Fire_PtDn
							{
								Id = Convert.ToInt32(dataGridViewRow2.Cells["colId"].Value),
								SprinklerNum = Convert.ToInt32(dataGridViewRow2.Cells["colPtnum"].Value),
								Diameter = Convert.ToInt32(dataGridViewRow2.Cells["colDiameter"].Value),
								DangerId = Convert.ToInt32(dataGridViewRow2.Cells["colDanId"].Value),
								AddInfo = AddSprinklerDiameter.NO
							});
						}
						if (YJKMessageBox.Show("确认要删除吗", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
						{
							int index2 = this.dgvFirePtNumInfo.CurrentRow.Index;
							list2.RemoveAt(index2);
							list2.Sort((Fire_PtDn x, Fire_PtDn y) => x.Diameter.CompareTo(y.Diameter));
							this.BindDGVInfo(list2, false);
							this.txtMaxDia.Text = Convert.ToString(list2.Last<Fire_PtDn>().Diameter);
						}
						else
						{
							this.blCheckTrue = true;
							this.beCheck = false;
						}
					}
				}
				else
				{
					YJKMessageBox.Show("请至少保留一条数据！");
				}
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}

		private void btnModify_Click(object sender, EventArgs e)
		{
			if (!this.JudgeSettingValue())
			{
				return;
			}
			this.K = Convert.ToDouble(this.cboK.Text);
			this.maxDiameter = Convert.ToInt32(this.txtMaxDia.Text);
			this.dangerId = Convert.ToInt32(this.cboWxdj.SelectedValue);
			this.SaveUserSetting();
			base.DialogResult = DialogResult.Yes;
			if (this.chkMin.Checked)
			{
				this.minDiameter = int.Parse(this.hyTxtMin.Text);
				return;
			}
			this.minDiameter = 0;
		}

		private void dgvFirePtNumInfo_CellClick(object sender, DataGridViewCellEventArgs e)
		{
			if (this.rowIndex == -1 || e.RowIndex != this.rowIndex)
			{
				this.editInfo = "修改";
				this.diameter = Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"].Value);
				this.ptNum = Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colPtnum"].Value);
			}
		}

		private void dgvFirePtNumInfo_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
		{
			if (!this.blCheckTrue)
			{
				e.Cancel = false;
				return;
			}
			if (this.beCheck)
			{
				e.Cancel = false;
				return;
			}
			if (this.dgvFirePtNumInfo.Columns[e.ColumnIndex].Name == "colPtnum" && e.RowIndex > 0)
			{
				if (e.FormattedValue == null)
				{
					YJKMessageBox.Show("喷头数不能为空！");
					e.Cancel = true;
				}
				if (!Regex.IsMatch(e.FormattedValue.ToString(), "^[0-9]\\d*$") || e.FormattedValue.ToString() == "0")
				{
					this.dgvFirePtNumInfo.Rows[e.RowIndex].ErrorText = "喷头数为正整数！";
					YJKMessageBox.Show("喷头数为正整数！");
					e.Cancel = true;
				}
				foreach (object obj in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
				{
					DataGridViewRow dataGridViewRow = (DataGridViewRow)obj;
					if (dataGridViewRow.Index != e.RowIndex && e.FormattedValue.ToString() == dataGridViewRow.Cells["colPtnum"].Value.ToString())
					{
						YJKMessageBox.Show("喷头数不能重复！");
						e.Cancel = true;
					}
				}
			}
			if (this.dgvFirePtNumInfo.Columns[e.ColumnIndex].Name == "colDiameter" && e.RowIndex > 0)
			{
				if (!Regex.IsMatch(e.FormattedValue.ToString(), "^[0-9]\\d*$") || e.FormattedValue.ToString() == "0")
				{
					this.dgvFirePtNumInfo.Rows[e.RowIndex].ErrorText = "管径为正整数！";
					YJKMessageBox.Show("管径尺寸为正整数！");
					e.Cancel = true;
				}
				foreach (object obj2 in ((IEnumerable)this.dgvFirePtNumInfo.Rows))
				{
					DataGridViewRow dataGridViewRow2 = (DataGridViewRow)obj2;
					if (dataGridViewRow2.Index != e.RowIndex && e.FormattedValue.ToString() == dataGridViewRow2.Cells["colDiameter"].Value.ToString())
					{
						YJKMessageBox.Show("管径尺寸不能重复！");
						e.Cancel = true;
					}
				}
			}
		}

		private void btnDelete_MouseEnter(object sender, EventArgs e)
		{
			this.beCheck = true;
		}

		private void btnDelete_MouseLeave(object sender, EventArgs e)
		{
			this.beCheck = false;
		}

		private void dgvFirePtNumInfo_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
		{
			if (this.editInfo != "添加")
			{
				this.editInfo = "修改";
				this.diameter = Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colDiameter"].Value);
				this.ptNum = Convert.ToInt32(this.dgvFirePtNumInfo.SelectedRows[0].Cells["colPtnum"].Value);
			}
		}

		private void chkMin_CheckedChanged(object sender, EventArgs e)
		{
			this.hyTxtMin.Enabled = this.chkMin.Checked;
		}

		private bool JudgeSettingValue()
		{
			bool flag = true;
			double textValue = this.GetTextValue(this.hyTxtMinDia, ref flag);
			if (!flag)
			{
				return flag;
			}
			if (textValue <= 0.0)
			{
				YJKMessageBox.Warning("最小标注管径不能为负值");
				this.hyTxtMinDia.Focus();
				this.hyTxtMinDia.SelectAll();
				flag = false;
				return flag;
			}
			textValue = this.GetTextValue(this.hyTxtFontHeight, ref flag);
			if (!flag)
			{
				return flag;
			}
			if (textValue <= 0.0)
			{
				YJKMessageBox.Warning("管径文字高度不能为负值");
				this.hyTxtFontHeight.Focus();
				this.hyTxtFontHeight.SelectAll();
				flag = false;
				return flag;
			}
			textValue = this.GetTextValue(this.hyTxtDistanceToLine, ref flag);
			if (!flag)
			{
				return flag;
			}
			if (textValue <= 0.0)
			{
				YJKMessageBox.Warning("标注距线距离不能为负值");
				this.hyTxtDistanceToLine.Focus();
				this.hyTxtDistanceToLine.SelectAll();
				flag = false;
				return flag;
			}
			return flag;
		}

		private double GetTextValue(System.Windows.Forms.TextBox txtBox, ref bool beCheck)
		{
			double result;
			try
			{
				double num = Convert.ToDouble(txtBox.Text);
				beCheck = true;
				result = num;
			}
			catch (Exception ex)
			{
				string message = ex.Message;
				YJKMessageBox.Warning("数值不能为空！");
				beCheck = false;
				result = 0.0;
			}
			return result;
		}

		private void cbThreeFour_CheckedChanged(object sender, EventArgs e)
		{
			if (this.cbThreeFour.Checked)
			{
				this.blThreeFour = true;
				return;
			}
			this.blThreeFour = false;
		}

		private string editInfo = "";

		public int dangerId;

		public double K;

		public int minDiameter;

		public List<Fire_PtDn> listPtNum = new List<Fire_PtDn>();

		private string sqlStr = "";

		public int maxDiameter;

		private int rowIndex = -1;

		private bool beCheck;

		private Document doc;

		private int diameter;

		private int ptNum;

		private SprinklerCalOperate ptCalOperate;

		private bool isAdd;

		private bool blCheckTrue = true;

		public bool blThreeFour;
	}
}
